﻿using ApiLib.AppStart;
using ApiLib.Cloud.Common;
using ApiLib.Cloud.Models;
using ApiLib.Models;
using Furion;
using Furion.Schedule;
using Microsoft.AspNetCore.Builder;

namespace ApiLib.Cloud;

/// <summary>
/// 系统配置
/// </summary>
public class CloudConfig : IBaseConfig
{
    /// <summary>
    /// 执行权重
    /// </summary>
    public int ExecuteWeight { get; set; } = 50;

    /// <summary>
    /// 
    /// </summary>
    public void Config()
    {
        GlobalConfig.RouteWhiteList.AddRange(new[] { "/api/Cloud/Register", "/api/Cloud/Health" });
        var serviceConfig = App.GetConfig<ServiceConfig>(nameof(ServiceConfig));
        if (serviceConfig == null)
        {
            return;
        }

        if (serviceConfig.IsZuul)
        {
            GlobalConfig.Configures.Add((app, _) => { app.UseMiddleware<MyCloudMiddleware>(); });
        }
        /*GlobalConfig.ServeName = serviceConfig.Name;
        if (serviceConfig.IsZuul)
        {
            GlobalConfig.Configures.Add((app, _) => { app.UseMiddleware<MyCloudMiddleware>(); });
            GlobalConfig.ScheduleOptionsBuilders.Add(builder => builder.AddJob<CloudHealthJob>(Triggers.PeriodSeconds(5)));
        }
        else
        {
            GlobalConfig.ScheduleOptionsBuilders.Add(builder =>
                builder.AddJob<CloudRegisterJob>(Triggers.PeriodMinutes(3).SetRunOnStart(true)));
        }*/
    }
}